<template>
	<view class="my-wallet">
		<view class="top-nav">
			<view class="status-bar"> </view>
			<view class="nav">
				<view class="left"> <uni-icons type="left" @tap="goBack" color="#FFF" size="20" /> </view>
				<view class="center"> 我的钱包 </view>
				<view class="right"> </view>
			</view>
		</view>
		<view class="content">
			<view class="price-box">
				<view class="price-name"> 分红余额(元)</view>
				<view class="price"> {{wallectInfo.company_deposit}} </view>
				<view class="total-box">
					<view class="item">
						<view class="label"> 今日分红 </view>
						<view class="value"> {{wallectInfo.company_deposit_day}} </view>
					</view>
					<view class="item">
						<view class="label"> 累计分红 </view>
						<view class="value"> {{wallectInfo.company_deposit_z}} </view>
					</view>
					<view class="item">
						<view class="label"> 已结算 </view>
						<view class="value"> {{wallectInfo.company_deposit_y}}</view>
					</view>
					<view class="item">
						<view class="label"> 未结算 </view>
						<view class="value"> {{wallectInfo.company_deposit_n}} </view>
					</view>
				</view>
				<view class="btn" @tap="goTX"> 立即提现 </view>
			</view>
			<!-- 明细记录 -->
			<view class="detail-record">
				<view class="details-name"> 明细记录 </view>
				<view class="details-time">
					<picker mode="date" :value="date" @change="dateChaneg" fields="month">
						<text> {{date}} </text>
						<uni-icons type="down" size="16" color="#999" />
					</picker>
				</view>
				<view class="detail-item" v-for="item in wallectList" :key="item" v-if="wallectList.length">
					<view class="detail-name">
						<view class="name"> {{item.info}} </view>
						<view class="time"> {{item.create_time}} </view>
						<view class="tips"> 分红收益来源 </view>
					</view>
					<view class="detail-price"> {{item.num}} </view>
				</view>
				<Empty txt="暂时没有符合的明细记录~" v-else/>
			</view>
		</view>
	</view>
</template>

<script setup>
	import { ref } from 'vue'
	import { onLoad, onReachBottom, onShow } from '@dcloudio/uni-app'
	import Empty from '@/components/Empty.vue'
	import { GetAgentWallectApi, GetWallectLogApi } from '@/service/agent.js'
	const wallectInfo = ref({
		company_deposit: '', // 余额
		company_deposit_day: '', // 今日分红后
		company_deposit_z: '', // 累计分红
		company_deposit_y: '',
		company_deposit_n: ''
	})
	const date = ref() // 选择的时间
	const page = ref(1)
	const pageSize = ref(15)
	const total = ref()
	const wallectList = ref([])
	const dateChaneg = (e) => {
		console.log(e.detail);
		const { detail } = e
		date.value = detail.value
		page.value = 1
		wallectList.value = []
		getWallectList()
	}
	const goBack = () => {
		uni.navigateBack()
	}
	const goTX = () => {
		uni.navigateTo({
			url: `/pages/riderPages/myWallet/myWallet?type=company_deposit&price=${wallectInfo.value.company_deposit}`
		})
	}
	// 获取钱包信息
	const getMyWallect = () => {
		GetAgentWallectApi({type: 'shop_deposit'}).then(res => {
			wallectInfo.value = res
			getWallectList()
		})
	}
	// 获取钱包记录
	const getWallectList = () => {
		let params = {
			status: 0,
			page: page.value,
			page_size: pageSize.value,
			type: 'company_deposit ',
			start_time: date.value + '-01',
			over_time: date.value + '-31'
		}
		GetWallectLogApi(params).then(res => {
			total.value = res.data?.total
			wallectList.value.push(...res.data?.data)
			console.log(wallectList.value);
		})
	}
	onShow(() => {
		getMyWallect()
		const y = new Date().getFullYear()
		const m = new Date().getMonth()
		date.value = y + '-' + (m + 1)
	})
	onReachBottom(() => {
		if(page.value*pageSize.value>=total.value) return
		page.value = page.value + 1
		getWallectList()
	})
</script>

<style scoped lang="scss">
	.my-wallet {
		.top-nav {
			height: 230px;
			background: linear-gradient( 360deg, rgba(253,181,108,0) 3%, #FFA37E 26%, #FF3B1E 97%);
			.status-bar {
				height: var(--status-bar-height);
				width: 100%;
			}
			.nav {
				padding: 0 12px;
				height: 44px;
				display: flex;
				justify-content: space-between;
				align-items: center;
				.left {
					width: 16px;
					height: 16px;
				}
				.center {
					color: #FFFFFF;
					font-size: 17px;
					font-weight: 500;
				}
				.right {
					width: 20px;
					height: 20px;
				}
			}
		}
		.content {
			padding: 10px 12px;
			box-sizing: border-box;
			transform: translateY(-142px);
			.price-box {
				height: 225px;
				padding: 20px 10px 10px;
				background: url('/static/icon/agent/top-bg.png') no-repeat center center;
				background-size: 100% 100%;
				box-sizing: border-box;
				.price-name {
					color: #666666;
					font-size: 14px;
					font-weight: 400;
					line-height: 22px;
					margin-bottom: 7px;
				}
				.price {
					color: #333333;
					font-size: 22px;
					font-weight: 700;
					line-height: 22px;
					margin-bottom: 20px;
				}
				.total-box {
					display: flex;
					align-items: center;
					height: 64px;
					background: #FFFFFF;
					border-radius: 10px;
					padding: 10px 12px 8px;
					margin-bottom: 20px;
					box-sizing: border-box;
					.item {
						flex: 1;
						.label {
							color: #908D8D;
							font-size: 12px;
							font-weight: 400;
							line-height: 22px;
							margin-bottom: 2px;
						}
						.value {
							color: #333333;
							font-size: 14px;
							font-weight: 500;
							line-height: 22px;
						}
					}
				}
				.btn {
					height: 40px;
					color: #FFFFFF;
					font-size: 17px;
					text-align: center;
					font-weight: bold;
					line-height: 40px;
					background: #FF3B1E;
					border-radius: 106px;
				}
			}
			.detail-record {
				padding: 15px 12px;
				box-sizing: border-box;
				.details-name {
					color: #333333;
					font-size: 14px;
					font-weight: 400;
					line-height: 16px;
					margin-bottom: 8px;
				}
				.details-time {
					color: #999999;
					font-size: 14px;
					font-weight: 400;
					line-height: 16px;
				}
				.detail-item {
					display: flex;
					justify-content: space-between;
					margin-top: 10px;
					border-radius: 10px;
					background-color: #fff;
					box-sizing: border-box;
					padding: 17px 10px 10px;
					.detail-name {
						.name {
							color: #333333;
							font-size: 14px;
							font-weight: 500;
							line-height: 16px;
							margin-bottom: 6px;
						}
						.time {
							color: #999999;
							font-size: 12px;
							font-weight: 400;
							line-height: 14px;
							margin-bottom: 6px;
						}
						.tips {
							color: #999999;
							font-size: 12px;
							font-weight: 400;
							line-height: 14px;
						}
					}
					.price {
						color: #333333;
						font-size: 16px;
						font-weight: 500;
						line-height: 22px;
					}
				}
			}
		}
	}
</style>
